/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Beans;

import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

/**
 *
 * @author Marco
 */

public class ClaseMail {
    private String from = "hotelesjava@gmail.com";
    private String password = "Passw0rdjavaweb";
    private InternetAddress addressTo;
    private String Subject = "Reserva Realizada";
    private String MessageMail = "";
    
    public ClaseMail(){}
    
    public void Enviar() throws MessagingException
    {
        try {
            System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
            Properties props = new Properties();
            props.put("mail.smtp.host", "smtp.gmail.com");  
            props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtp.auth", "true");
//            props.put("mail.smtp.user", "usuario");
            props.put("mail.smtp.port", 587);
            //
            SMTPAuthenticator auth = new SMTPAuthenticator( from, password );
            Session session = Session.getInstance(props, auth);
            session.setDebug(false);
            //Se crea destino y origen del mensaje
            MimeMessage mimemessage = new MimeMessage(session);
            InternetAddress addressFrom = new InternetAddress( from );
            mimemessage.setFrom(addressFrom);
            mimemessage.setRecipient(Message.RecipientType.TO, addressTo);
            mimemessage.setSubject( Subject );
            // Se crea el contenido del mensaje
            MimeBodyPart mimebodypart = new MimeBodyPart();
            mimebodypart.setText( MessageMail );
            mimebodypart.setContent( MessageMail, "text/html");
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(mimebodypart);            
            mimemessage.setContent(multipart);            
            mimemessage.setSentDate(new Date());
            Transport.send(mimemessage);
        } catch (MessagingException ex) {
            throw ex;
        }
        
    }
        public void setTo(String mail){
            try{
            addressTo = new InternetAddress(mail);
            }
            catch(AddressException ex){
                
            }
            
        }
        public void setMessage(String value){ this.MessageMail = value; }
}
